﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UCL.Powersource.Analysis;

namespace UCL.Powersource
{
    public class StatisticManagerQueueUpdatedEventArgs
    {

        public IStatisticManagerQueueItem Item { get; private set; }
        public QueuedItemStatus ItemStatus { get; private set; }
        public Exception ItemComputationException {get;private set;}
        public int WaitingStatsCount { get; private set; }
        public int FinishedStatsCount { get; private set; }
        public string CurrentAction { get; private set; }
        public string CurrentActionMessage { get; private set; }
        public bool IsCalculating { get; private set; }

        public StatisticManagerQueueUpdatedEventArgs(IStatisticManagerQueueItem item, QueuedItemStatus status, Exception exc, IStatisticManagerQueue mq)
            :this(item,status,exc,mq,null,null)
        {
        }

        public StatisticManagerQueueUpdatedEventArgs(IStatisticManagerQueueItem item, QueuedItemStatus status, Exception exc, IStatisticManagerQueue mq, string format, params object[] args)
        {
            Item = item;
            ItemStatus = status;
            ItemComputationException = exc;
            this.IsCalculating = mq.IsCalculating;
            this.WaitingStatsCount = mq.WaitingStatsCount;
            this.FinishedStatsCount = mq.FinishedStatsCount;
            this.CurrentAction = mq.CurrentAction;
            if (!string.IsNullOrWhiteSpace(format)) CurrentActionMessage = string.Format(format, args);
        }

        public override string ToString()
        {
            string item="#NULL";
            //string queue = "#NULL";
            string exc = "";
            if (Item!=null) item=Item.ToString();
            if (ItemComputationException!=null) exc=string.Format("![Exc:{0} {1}]",ItemComputationException.GetType().Name,ItemComputationException.Message);

            return string.Format("Item: {0}, Exc: {1}, Queue: [IsCalculating={2}, FS={3}, WS={4}, Action={5} - {6}", item, exc, IsCalculating, FinishedStatsCount, WaitingStatsCount, CurrentAction, CurrentActionMessage);
        }

        //public StatisticManagerQueueUpdatedEventArgs(StatisticManagerQueueItem item, QueuedItemStatus status, Exception exc, bool isCalculating)
        //{
        //    Item = item;
        //    ItemStatus = status;
        //    ItemComputationException = exc;
        //    this.IsCalculating = isCalculating;
        
        //}

    }
}
